import fetcher from "./Fetcher";
import {Pageable} from "../utils/Page";

export function searchPlaceRegion(keyword: string, region: String, pageable: Pageable) {
    return fetcher.get<SearchPlaceResponse>("/tencentPositions/searchPlaceRegion", {
        keyword, region,
        ...pageable.toRequestParams(),
    })
}

export function searchPlaceNearby(keyword: string, longitude:number,latitude:number, pageable: Pageable) {
    return fetcher.get<SearchPlaceResponse>("/tencentPositions/searchPlaceNearby", {
        keyword, longitude,
        latitude,
        ...pageable.toRequestParams(),
    })
}


export interface SearchPlaceResponse {
    status: number;
    message: string;
    count?: number;
    data: SearchPlacePoiItemResponse[];
}

export interface SearchPlacePoiItemResponse {
    id: string;
    title: string;
    address: string;
    tel?: string;
    category: string;
    type: number;
    location: SearchPlacePoiItemLocationResponse;
    ad_info: SearchPlacePoiItemAdInfoResponse; // JSON 属性名为 "ad_info"
}

export interface SearchPlacePoiItemLocationResponse {
    lat: number;
    lng: number;
}

export interface SearchPlacePoiItemAdInfoResponse {
    adcode: string;
    province: string;
    city: string;
    district: string;
}

export function searchSuggestion(keyword:string,pageable:Pageable,region?:string,){
    return fetcher.get<SearchSuggestionResponse>("/tencentPositions/searchSuggestion",{
        keyword,
        region,
        ...pageable.toRequestParams(),
    })
}

export interface SearchSuggestionResponse {
    status: number;
    message: string;
    count?: number;
    data: SearchSuggestionPoiItemResponse[];
}

export interface SearchSuggestionPoiItemResponse {
    id: string;
    title: string;
    address: string;
    tel?: string;
    category: string;
    type: number;
    location: SearchSuggestionLocationResponse;
    adcode: string;
    province: string;
    city: string;
    district: string;
}

export interface SearchSuggestionLocationResponse {
    lat: number;
    lng: number;
}